package org.dromara.learning_xq.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.learning_xq.entity.AsViewPaper;
import org.dromara.learning_xq.entity.AsViewingJobs;
import org.dromara.learning_xq.mapper.AsViewPaperMapper;
import org.dromara.learning_xq.service.AsViewPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AsViewPaperServiceimpl extends ServiceImpl<AsViewPaperMapper, AsViewPaper> implements AsViewPaperService {


    @Autowired
    private AsViewPaperMapper asViewPaperMapper;

    /**
     * 查询并返回所有的 AsViewingJobs 记录
     * <p>
     * 此方法通过调用 asViewingJobsMapper 的 selectList 方法，传入 null 参数
     * 以获取数据库中所有的 AsViewingJobs 记录无需任何条件限制
     *
     * @return 包含所有 AsViewingJobs 记录的列表
     */
    @Override
    public List<AsViewPaper> selectAsViewPaperService() {
        return asViewPaperMapper.selectList(null);
    }

    @Override
    public List<AsViewPaper> selectAsViewingJobsCondition(String state, String name, String group) {
        // 创建一个 QueryWrapper 实例
        QueryWrapper<AsViewPaper> queryWrapper = new QueryWrapper<>();

        // 状态条件查询
        if (state != null && !state.isEmpty()) {
            queryWrapper.eq("`state`", state);
        }
        if (group != null && !group.isEmpty()) {
            queryWrapper.eq("`group`", group);
        }

        // 姓名模糊查询
        if (name != null && !name.isEmpty()) {
            queryWrapper.like("`name`", name);
        }

        // 使用 MyBatis-Plus 的查询方法获取结果
        return asViewPaperMapper.selectList(queryWrapper);
    }
}
